class FrontLog {
  // constructor() { }
  send ({ content = '', moduleName = '', linesOfCode = 0, templeName = '' }) {
    const { user } = window.$app
    let params = {
      content,
      moduleName,
      linesOfCode,
      templeName,
      time: new Date().getTime(),
      userName: user.realName || '',
      userId: user.userId || '',
      orgId: user.orgId || '',
      orgName: user.orgName
    }
    // console.log('write log:', params)
    if (window.$app.appType === 'pc') {
      window.$twpc.weblog.writelog.send(params)
    } else if (window.$app.appType === 'pad') {
      if (window.creativeJSCallbackForOther && window.creativeJSCallbackForOther.addLog) {
        window.creativeJSCallbackForOther.addLog(JSON.stringify(params))
      } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.addLog) {
        window.webkit.messageHandlers.addLog.postMessage(JSON.stringify(params))
      }
    }
  }
  uplog () {
    console.log('uplog')
    if (window.$app.appType === 'pc') {
      window.$twpc.weblog.uplog.send()
    } else if (window.$app.appType === 'pad') {
      // todo
      console.log('uplog not impl')
    }
  }
}

export const TwFrontLog = {
  install (app, config) {
    const twFrontLog = new FrontLog(config)
    window.$twFrontLog = twFrontLog
    app.config.globalProperties.$twFrontLog = window.$twFrontLog
  }
}
